#pragma once
#define _CRT_SECURE_NO_WARNINGS
#include <fstream>
using namespace std;
namespace lin {
	namespace utility {

#define debug(format, ...) \
		Logger::instance()->log(Level::DEBUG, __FILE__, __LINE__, format, ##__VA_ARGS__)

#define info(format, ...) \
		Logger::instance()->log(Level::INFO, __FILE__, __LINE__, format, ##__VA_ARGS__)

#define warn(format, ...) \
	    Logger::instance()->log(Level::WARN, __FILE__, __LINE__, format, ##__VA_ARGS__)

#define error(format, ...) \
    Logger::instance()->log(Level::ERROR, __FILE__, __LINE__, format, ##__VA_ARGS__)

#define fatal(format, ...) \
    Logger::instance()->log(Level::FATAL, __FILE__, __LINE__, format, ##__VA_ARGS__)
		enum Level
		{
			DEBUG = 0,
			INFO,
			WARN,
			ERROR,
			FATAL,
			LEVEL_COUNT
		};
		
		class Logger {
			

		private:
			Logger();
			void rotate();


		public:
			static Logger* instance();
			void log(Level level, const char* file, int line, const char* format, ...);
			void close();
			void open(const string& filename);
			void max(int bytes);
			void level(int level);

		private:
		static Logger* m_instance;
		static const char* s_level[LEVEL_COUNT];
		// 写入文件
		ofstream m_fout;
		string m_filename;

		int m_max;
		int m_len;
		int m_level;
		};




	}
}